package cm.studapp.adapters;

import cm.studapp.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;



@SuppressLint({ "ResourceAsColor", "ResourceAsColor" })
public class WeekElemAdapter extends BaseAdapter {
	private Context context;
	private final int[] mobileValues;
	private final String[] values=generator();
	private static int hour=0;
	
	public WeekElemAdapter(Context context, int[] mobileValues) {

		this.context = context;
		this.mobileValues = mobileValues;

	}

	@SuppressLint({ "ResourceAsColor", "ResourceAsColor" })
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View gridView;


			gridView = new View(context);


			if(values[position].equals("hour")){
				gridView = inflater.inflate(R.layout.week_view_hour_elem, null);	
				TextView aux = (TextView) gridView.findViewById(R.id.grid_item_hour);
				int hora=position/8;
				aux.setText(hora+":00");
			}
			else{
				// get layout from mobile.xml
				/*gridView = inflater.inflate(R.layout.week_view_rep_elem, null);
				ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);			
				if(values[position].equals("good")){
				imageView.setImageResource(R.drawable.ok);
				}
				else{
				imageView.setImageResource(R.drawable.wrong);
				}
				*/
				gridView = inflater.inflate(R.layout.week_view_rep_elem_grad, null);
				LinearLayout layoutColor = (LinearLayout) gridView.findViewById(R.id.grid_layout);			
				if(values[position].equals("good")){
					layoutColor.setBackgroundColor(Color.GREEN);
				}
				else{
					layoutColor.setBackgroundColor(Color.RED);
				}
			}

		return gridView;
	}
	
	private boolean isHour(int index){
		int i;
		for(i=0;i<=index;i=(i+8)){
			if(index==i){
				return true;
			}
		}
		return false;
	}

	@Override
	public int getCount() {
		return values.length;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	public String[] generator(){
		String[] aux = new String[8*24];
		for(int i=0; i<(8*24);i++){
			if(isHour(i)){
				aux[i] = "hour";
			}
			else{
				if(Math.random()>0.5)
					aux[i]="good";
				else
					aux[i]="wrong";
			}
		}
		return aux;
	}

}
